package com.tuniu.agents.common.entity.trip;

import java.util.List;

import com.tuniu.agents.common.vo.ApiResponse;

/**
 * Trip similarity matching results
 */
public class TripSearchResponse extends ApiResponse<List<TripSearchResponse.Data>> {
    
    
    
    public static class Data {
        private String product_id;
        private Double similarity_score;
        private String itinerary_plan;
        private Resource resource;

        public String getProduct_id() {
            return product_id.split("-")[0];
        }

        public void setProduct_id(String product_id) {
            this.product_id = product_id;
        }

        public Double getSimilarity_score() {
            return similarity_score;
        }

        public void setSimilarity_score(Double similarity_score) {
            this.similarity_score = similarity_score;
        }

        public String getItinerary_plan() {
            return itinerary_plan;
        }

        public void setItinerary_plan(String itinerary_plan) {
            this.itinerary_plan = itinerary_plan;
        }

        public Resource getResource() {
            return resource;
        }

        public void setResource(Resource resource) {
            this.resource = resource;
        }

        public static class Resource {
            private List<Product> product;
            
            public static class Product {
                private String name;
                private String url;
                public String getName() {
                    return name;
                }
                public void setName(String name) {
                    this.name = name;
                }
                public String getUrl() {
                    return url;
                }
                public void setUrl(String url) {
                    this.url = url;
                }
            }

            public List<Product> getProduct() {
                return product;
            }

            public void setProduct(List<Product> product) {
                this.product = product;
            }
        }

        
    }
    public String toMarkdown() {
        if (data == null || data.isEmpty()) {
            return "No matching trip information available";
        }

        StringBuilder resultBuilder = new StringBuilder();
        resultBuilder.append("### Trip Matching Results\n\n");
        
        // Table header
        resultBuilder.append("| Product ID | Product Name | Itinerary | Similarity |\n");
        resultBuilder.append("|:--------|:--------|:--------|:------|\n");
        
        for (Data d : data) {
            String productName = d.getResource() != null && d.getResource().getProduct() != null && !d.getResource().getProduct().isEmpty() 
                ? d.getResource().getProduct().get(0).getName().replace("|", "\\|") 
                : "No name available";
                
            String itinerary = d.getItinerary_plan() != null ? d.getItinerary_plan().replace("|", "\\|") : "No itinerary available";
            String similarity = d.getSimilarity_score() != null ? String.format("%.2f", d.getSimilarity_score()) : "0.00";
            
            resultBuilder.append(String.format("| %s | %s | %s | %s |\n",
                d.getProduct_id(),
                productName,
                itinerary,
                similarity
            ));
        }
        
        return resultBuilder.toString();
    }
    
    
}
